//
//  RootViewController.m
//  UIhomework_14
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "RootViewController.h"
#import "activityModel.h"
#import "ActivityTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "RootViewController2.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface RootViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) NSMutableArray *actModel;

@end

@implementation RootViewController
-(void)dealloc{
    [_actModel release];
    [_tableView release];
    [_arr release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //self.view.backgroundColor = [UIColor redColor];
    self.navigationItem.title = @"活动";
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
    
 
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [_tableView registerClass:[ActivityTableViewCell class] forCellReuseIdentifier:@"cell"];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView release];
    
    [self dataHandle];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//数据处理
- (void)dataHandle{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
    self.arr = [NSMutableArray arrayWithContentsOfFile:path];
    self.actModel = [NSMutableArray array];
    for (NSDictionary *dic in _arr) {
        activityModel *model = [activityModel activityModel];
        [model setValuesForKeysWithDictionary:dic];
        [_actModel addObject:model];
    }
   // NSLog(@"%@", _actModel);
    
    
}

//协议部分

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _actModel.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 250;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    RootViewController2 *VC = [[RootViewController2 alloc] init];
    VC.modelArr = _actModel;
    VC.index = indexPath;
    [self.navigationController pushViewController:VC animated:YES];
    [VC release];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ActivityTableViewCell *cell = [[ActivityTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    cell.imgView.image = [UIImage imageNamed:@"bg_eventlistcell.png"];
    activityModel *model = _actModel[indexPath.row];
    cell.label.text = model.title;
    cell.imgViewSmall1.image = [UIImage imageNamed:@"icon_date@2x.png"];
    NSString *str = model.begin_time;
    NSString *str1 = [str substringFromIndex:5];
    NSString *str2 = model.end_time;
    NSString *str3 = [str2 substringFromIndex:5];
    NSString *str4 = [NSString stringWithFormat:@"%@ -- %@", str1, str3];
    cell.labelSmall1.text = str4;
    cell.imgViewSmall2.image = [UIImage imageNamed:@"icon_spot@2x.png"];
    cell.labelSmall2.text = model.address;
    cell.imgViewSmall3.image = [UIImage imageNamed:@"icon_catalog@2x.png"];
    cell.labelSmall3.text = [NSString stringWithFormat:@"类型: %@", model.category_name];
    cell.labelDown1.text = @"感兴趣";
    cell.labelDownText1.text = [NSString stringWithFormat:@"%@", model.wisher_count];
    cell.labelDown2.text = @"参加";
    cell.labelDownText2.text = [NSString stringWithFormat:@"%@", model.participant_count];
   [cell.imgViewRight sd_setImageWithURL:[NSURL URLWithString:model.image]];
    

    return cell;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
